<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>wrap (REXML::Formatters::Pretty)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File patches.rb, line 12</span>
      <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">wrap</span>(<span class="ruby-identifier">string</span>, <span class="ruby-identifier">width</span>)
<span class="ruby-comment cmt">#         p(&quot;wrap(&quot; + string.to_s + &quot;,&quot; + width.to_s + &quot;)&quot;)</span>
        <span class="ruby-comment cmt"># Recursively wrap string at width.</span>
        <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">string</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">string</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-identifier">width</span>
        <span class="ruby-identifier">place</span> = <span class="ruby-identifier">string</span>.<span class="ruby-identifier">rindex</span>(<span class="ruby-value str">' '</span>, <span class="ruby-identifier">width</span>) <span class="ruby-comment cmt"># Position in string with last ' ' before cutoff</span>
        <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">string</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">place</span>        <span class="ruby-comment cmt"># too wide, but no spaces to break</span>
        <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">string</span>[<span class="ruby-value">0</span>,<span class="ruby-identifier">place</span>] <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;\n&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">wrap</span>(<span class="ruby-identifier">string</span>[<span class="ruby-identifier">place</span><span class="ruby-operator">+</span><span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>], <span class="ruby-identifier">width</span>)
      <span class="ruby-keyword kw">end</span></pre>
</body>
</html>